//
//  ConsumptionHistoryViewController.m
//  Doctors
//
//  Created by 王森 on 16/4/22.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "ConsumptionHistoryViewController.h"
#import "PatientTableViewCell.h"
#import "MJRefresh.h"
#import "LicensedOrderModel.h"

@interface ConsumptionHistoryViewController ()

@end

@implementation ConsumptionHistoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addLeftBackBtn:nil];
    self.title=@"消费记录";

    [self customTableView];
    [self requestData];

    __weak typeof(self)weakSelf=self;
    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self.dataArray removeAllObjects];
        
        
          [weakSelf requestData];
        
        
    }];
    
    [self setFooterfresh:^{
        weakSelf.page++;
        
        [weakSelf requestData];

    }];
    
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    self.tableview.mj_header.automaticallyChangeAlpha = YES;
    
    [self registerNib:@"PatientTableViewCell"];
    
    
    //    UINib *ordernib=[UIView loadNibNamed:@"PatientTableViewCell" bundle:nil];
    //    [self.tableview registerNib:ordernib forCellReuseIdentifier:@"PatientTableViewCell"];//注册cell
    //
    
    
    // Do any additional setup after loading the view from its nib.
}

-(void)requestData{
    [self addProgressHUD];
    
    [self requestApiWithUrl:@"/order/getUserOrderList" dictionary:@{@"artisanId":[self getArtisanId],@"userId":self.userId,@"page":[NSString stringWithFormat:@"%d",self.page],@"size":@"10"} isCache:NO success:^(id responseObject) {
        NSLog(@"%@",responseObject);
        
        [self removeStatuslable];
        
        NSArray *array=responseObject[@"orderList"];
        if (array.count==0) {
            self.page--;
            
        }
        for (NSDictionary *dic in array) {
            
            LicensedOrderModel *model=[[LicensedOrderModel alloc]initWithDic:dic];
            [self.dataArray addObject:model];
            
        }
        
        [self.tableview reloadData];
        

    } faild:^(NSError *error) {
        self.page--;
        [self removeStatuslable];

    }];
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    __weak typeof(self)weakSelf=self;
    //
    //    OrderModel *model=self.dataArray[indexPath.row];
    
    PatientTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PatientTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.jianTouImg.hidden=YES;
        [cell xiaoFeiFuZhi:self.dataArray[indexPath.row]];
    
    
    //    __weak typeof(self)weakSef=self;
    
    
    
    return cell;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.dataArray.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 123;
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
 
    NSLog(@"请重写方法");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
